import { fileURLToPath, URL } from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue({
      script: {
        defineModel: true,
        propsDestructure: true,
        compilerOptions: {
          isCustomElement: (tag) => tag.includes('-')
        },
        reactivityTransform: true,
        defaultExport: true
      }
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  esbuild: {
    target: 'esnext',
    tsconfigRaw: {
      compilerOptions: {
        allowJs: true,
        noImplicitAny: false,
        isolatedModules: false,
        preserveValueImports: false,
        skipLibCheck: true
      }
    }
  },
  server: {
    host: '0.0.0.0',
    proxy: {  
      '/api': {  
        target: 'http://localhost:63040', // 后端服务器的地址  
        changeOrigin: true,  
        rewrite: (path) => path.replace(/^\/api/, '')  
      },
      '/socket': {
        target: 'ws://localhost:63040',
        ws: true,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/socket/, '')
      }
    },
  }
})
